<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情页</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../static/css/home.min.css">
    <style>
        body{
            background: url("../static/images/bg.png");
        }

        .m-text{
            font-weight: 300 !important;
            letter-spacing: 1px !important;
            line-height: 1.5 !important;
            font-family: 宋体;
        }

         .m-black{
            color: #333 !important;
        }
    </style>
</head>
<body>
    <!-- 首页 -->
    <nav th:replace="_fragments :: menu(0)" class="ui inverted segment stacked m-padding-smaller">
        <div class="ui container">
            <div class="ui inverted secondary stacked menu">
                <h2 class="ui teal header item">Blog</h2>
                <a href="#" class="item"><i class="mini home icon"></i> 首页</a>
                <a href="#" class="item"><i class="mini idea icon"></i> 分类</a>
                <a href="#" class="item"><i class="mini tag icon"></i> 标签</a>
                <a href="#" class="item"><i class="mini clone icon"></i> 归档</a>
                <a href="#" class="item"><i class="mini info icon"></i> 关于我</a>
                <div class="right item">
                    <div class="ui icon input">
                        <input type="text" placeholder="search...">
                        <i class="search link icon"></i>
                    </div>
                </div>
            </div>
        </div>
    </nav>
    <!-- 首页 -->

    <!--    中间部分-->
    <div class="m-padding-big m-container-small">
        <div class="ui container">
            <!-- 头部 -->
            <div class="ui top attached segment">
                <div class="ui horizontal link list">
                    <div class="item">
                        <img th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image m-size-icon-small">
                        <div class="content">
                            <a class="header teal" th:text="${blog.user.nickname}">刘军民</a>
                        </div>
                        <div class="item m-padding-left-small" style="display: inline-block">
                            <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}"></span>
                        </div>
                        <div class="item m-padding-left-small" style="display: inline-block">
                            <i class="eye icon"></i> <span th:text="${blog.views}"></span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 图片 -->
            <div class="ui attached segment" align="center">
                <img th:src="@{${blog.firstPicture}}" style="height: auto; width: auto" alt="" class="ui center aligned fluid rounded image">
            </div>
            <!-- 正文 -->
            <div class="ui attached segment">
                <div class="ui right aligned basic segment">
                    <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
                </div>
                <h2 class="ui header center aligned" th:text="${blog.title}">原创博文</h2>
                <div id="content" th:utext="${blog.content}">
                </div>
                <!-- 标签 -->
                <div style="padding-left: 1em; margin-top: 2em">
                    <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">SpringBoot</div>
                </div>
                <!-- 赞赏 -->
                <div class="ui center aligned basic segment">
                    <button class="ui payButton orange basic circular button">赞赏</button>
                </div>
                <div class="ui floating payQR popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important">
                            <div class="image">
                                <img src="/images/AliPay.jpg" th:src="@{/images/AliPay.jpg}" alt="" class="ui rounded bordered image" style="width: 120px; display: inline">
                                <div>支付宝</div>
                            </div>
                            <div class="image">
                                <img src="/images/WeChatPay.png" th:src="@{/images/WeChatPay.png}" alt="" class="ui rounded bordered image" style="width: 120px; display: inline">
                                <div>微信</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 博客信息 -->
            <div class="ui attached positive message">
                <div class="ui grid">
                    <div class="eleven wide column">
                        <ui class="list">
                            <li>作者：<span th:text="${blog.user.nickname}"></span> <a th:href="@{/about}" target="_blank">（联系作者）</a> </li>
                            <li>发表时间：<span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm')}"></span> </li>
                            <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                            <li>公众号转载：请在文本添加作者公众号二维码</li>
                        </ui>
                    </div>
                    <div class="five wide column">
                        <img src="/images/WeChat.png" th:src="@{/images/WeChat.png}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                    </div>
                </div>
            </div>
            <!-- 留言区域 -->
            <div class="ui attached segment">
            <!--留言区域列表-->
                <div id="comment-container" class="ui teal segment">
                    <div th:fragment="commentList">
                        <div class="ui threaded comments">
                            <h3 class="ui dividing header">评论</h3>
                            <div class="comment" th:each="comment : ${comments}">
                                <a class="avatar">
                                    <img src="/images/green.jpg" th:src="@{${comment.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author">
                                        <span th:text="${comment.nickname}">马特</span>
                                        <div class="ui mini basic teal left pointing label m-padding-tiny" th:if="${comment.adminComment}">博主</div>
                                    </a>
                                    <div class="metadata">
                                        <span class="date" th:text="${#dates.format(comment.createTime, 'yyyy-MM-dd HH:mm')}">今天下午5:42</span>
                                    </div>
                                    <div class="text" th:text="${comment.content}">多么艺术！</div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="马特" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">
                                            回复
                                        </a>
                                    </div>
                                </div>
                                <div class="comments" th:if="${#arrays.length(comment.replyComments)} > 0">
                                    <div class="comment" th:each="reply : ${comment.replyComments}">
                                        <a class="avatar">
                                            <img src="/images/green.jpg" th:src="@{${reply.avatar}}">
                                        </a>
                                        <div class="content">
                                            <a class="author">
                                                <span th:text="${reply.nickname}">小红</span><div class="ui mini basic teal left pointing label m-padding-tiny" th:if="${comment.adminComment}">博主</div>
                                                &nbsp;<span class="m-teal" th:text="'@' + '&nbsp;'+ ${reply.parentComment.nickname}">小蓝</span>
                                            </a>
                                            <div class="metadata">
                                                <span class="date" th:text="${#dates.format(reply.createTime, 'yyyy-MM-dd HH:mm')}">今天下午5:42</span>
                                            </div>
                                            <div class="text" th:text="${reply.content}">多么艺术！</div>
                                            <div class="actions">
                                                <a class="reply" data-commentid="1" data-commentnickname="马特" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">
                                                    回复
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="ui form">
                    <input type="hidden" name="blog.id" th:value="${blog.id}">
                    <input type="hidden" name="parentComment.id" value="-1">
                    <div class="field">
                        <textarea name="content" id="" cols="30" rows="10" placeholder="请输入评论内容"></textarea>
                    </div>
                    <div class="fields">
                        <div class="field">
                            <div class="ui left icon input">
                                <i class="user icon"></i>
                                <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.nickname}">
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui left icon input">
                                <i class="mail icon"></i>
                                <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                            </div>
                        </div>
                        <div class="field">
                           <button type="button" id="commentpost-btn" class="ui teal button"><i class="edit icon"></i>发送</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 中间部分 -->


    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>

    <!--    底部-->
    <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padding-large">
        <div class="ui center aligned container">
            <div class="ui inverted divided grid">
                <div class="three wide column">
                    <div class="item">
                        <img src="/images/WeChat.png" class="ui rounded image" alt="" style="width: 100px">
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">最新项目</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">最新项目</a>
                        <a href="#" class="item">最新项目</a>
                        <a href="#" class="item">最新项目</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email:1792619448@qq.com</a>
                        <a href="#" class="item">QQ:1792619448</a>
                        <a href="https://github.com/liujunminx" class="item">GitHub-></a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header">关于博客</h4>
                    <div class="ui inverted link list">
                        <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客，分享自己学习历程中的笔记，项目，感想，希望能和大家交流学习</p>
                    </div>
                </div>
            </div>
            <div class="ui inverted divider section"></div>
            <p class="m-text-thin m-text-spaced m-opacity-mini">Copyright © 2019 Lemon Designed by Liu JunMin</p>
        </div>
    </footer>

    <span th:replace="_fragments::script"> </span>

    <script type="text/javascript" th:inline="javascript" th:object="${blog}">
        //初始化加载commentList
        $(function () {
            $("#comment-container").load(/*[[@{/comments/{id}(id=*{id})}]]*/"/comments/40")
        });

        $(document).ready(function(){
            $(".payButton.button").popup({
                popup: $('.payQR.popup'),
                on: 'click',
                position: 'bottom center'
            });
        });

        $('.ui.form').form({
            fields: {
                title: {
                    identifier: 'content',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入评论内容'
                    }]
                },
                content: {
                    identifier: 'nickname',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入你的名字'
                    }]
                },
                type: {
                    identifier: 'email',
                    rules: [{
                        type: 'email',
                        prompt: '请输入正确的邮箱地址'
                    }]
                }
            }
        });

        $('#commentpost-btn').click(function () {
            var flag = $('.ui.form').form("validate form");
            if (flag){
                console.log("校验成功");
                postData();
            } else {
                console.log("校验失败");
            }
        });

        /**
         * 按钮 ajax形式传输评论信息 路径/comments
         */
        function postData() {
           $("#comment-container").load(/*[[@{/comments}]]*/"/comments", {
               "parentComment.id": $("[name='parentComment.id']").val(),
               "blog.id": $("[name='blog.id']").val(),
               "nickname": $("[name='nickname']").val(),
               "email": $("[name='email']").val(),
               "content": $("[name='content']").val()
           }), function (responseTxt, statusTxt, xhr) {
               clearContent();
           }
        }

        function clearContent() {
            $("[name='content']").val('');
            //赋值为-1，初始为空
            $("[name='parentComment.id']").val('-1');
            $("[name='content']").attr("placeholder", "请输入评论信息...");
        }

        /**
         * 清空content，并且添加“@某某”字样
         * @param obj
         */
        function reply(obj) {
            var commentId = $(obj).data("commentid");
            var commentNickname = $(obj).data("commentnickname");
            $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
            $("[name='parentComment.id']").val(commentId);
        }
    </script>
</body>
</html>